home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 24
/
Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso
/
Aminet
/
biz
/
dbase
/
Aminet2DB.lha
/
CSV2TSV.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1998-01-28
|
1KB
|
46 lines
/*
* CSV2TSV.rexx
* Converts comma-separated values to tab-separated values.
* $VER: CSV2TSV.rexx 1.0 (6.12.97)
* By Deok-Min Yun
*/
OPTIONS RESULTS
PARSE ARG filename
tab = '09'x
IF OPEN('DataFile', filename, 'R') = 1 THEN DO
IF OPEN('SaveFile', filename||'.TSV', 'W') = 1 THEN DO
DO FOREVER
temp = READLN('DataFile')
IF EOF('DataFile') THEN BREAK
ptr = 1
DO WHILE (INDEX(temp, ',', ptr) ~= 0) | (INDEX(temp, '"', ptr) ~= 0)
comma = INDEX(temp, ',', ptr)
quote1 = INDEX(temp, '"', ptr)
IF (quote1 = 0) | (quote1 > comma) THEN DO
ptr = comma
temp = OVERLAY(tab, temp, ptr)
ptr = ptr + 1
END
ELSE IF (comma = 0) | (quote1 < comma) THEN DO
ptr = quote1
temp = DELSTR(temp, ptr, 1)
quote2 = INDEX(temp, '"', ptr)
IF quote2 ~= 0 THEN DO
ptr = quote2
temp = DELSTR(temp, ptr, 1)
END
ELSE ptr = LENGTH(temp)
END
END
CALL WRITELN('SaveFile', temp)
END
CALL CLOSE('SaveFile')
END
ELSE SAY "Couldn't create a new file."
CALL CLOSE('DataFile')
END
ELSE SAY "Couldn't open original file."